import api from '@/api'

const state = {
    //分类数据
    categoryList: [],
    //轮播图数据
    bannerList: []
}

const actions = {
    //获取首页数据
    async getHomeData({ commit }) {
        let result = await api.reqHomeData();
        if (result.code == 200) {
            commit("SET_HOME_DATA", result.data);
        }
    }
}

const mutations = {
    SET_HOME_DATA(state, data) {
        state.categoryList = data.categories || [];
        state.bannerList = data.banners || [];
    }
}

const getters = {}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}